How to disable remote access to the root user?
Hi! On server-related forums, I realized the following - very often people don't know how to disable remote access to the root user. However, this is a very important step in ensuring the security of your server, and today I will tell you how to do it. I already talked about this a few years ago, but now I decided to supplement and slightly modify this guide to make it easier for novice users.
How can I disable remote access to the Root user?
To disable remote access, you must first create a user to work with. The user is created using the following command:useradd NAMESo you create a new account and give it a password. To grant Sudo(administrator) access to work, use the following command:
passwd NAME
usedmod -aG sudo NAMENow disable remote access using the following commands First, open the SSH Config file using the following command
sudo nano /etc/ssh/sshd_configHere, find the PermitRootLogin yes item and change its value to no. After that, use the following command to restart
ssh sudo service ssh restartNow your root user is unavailable for remote connection and in order for all changes to be applied, you need to restart the server using the reboot command.
Is it possible to enable remote access to the root user?
Yes, after disabling remote access, you can turn it back on, and that's exactly why we granted administrator rights to the newly created user. Of course, I do not recommend turning back on remote access for the root user because this reduces security, but if there is no other way out, then use the same commands as when disabling. First, open the SSH Config file using the following commandsudo nano /etc/ssh/sshd_configHere, find PermitRootLogin no and change its value to yes. After that, use the following command to restart the ssh service
sudo service ssh restart
Now, after restarting SSH, access to your root user is reactivated and you can use it. However, this is done only as a last resort and only by the most senior system administrator. However, after the necessary actions have been performed, please disable access again, otherwise you risk that your root user may be hacked.

